
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>设计模式六大原则是什么？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>设计模式六大原则是什么？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">原则</div>
          <div class="card-question">单一职责原则 (SRP) 的核心定义是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">原则</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">一个类应当仅有一个理由引起变化，也就是说，一个类应该只有一个职责。</div>
          </div>
          <div class="card-source">来源: 1. 单一职责原则（Single Responsibility Principle, SRP）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">原则</div>
          <div class="card-question">开放封闭原则 (OCP) 对软件实体的扩展和修改提出了怎样的要求？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">原则</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">软件实体（类、模块、函数等）应当对扩展开放，对修改封闭。这意味着一个类或模块应当能够在不修改其源代码的情况下，进行功能的扩展。</div>
          </div>
          <div class="card-source">来源: 2. 开放封闭原则（Open/Closed Principle, OCP）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">原则</div>
          <div class="card-question">里氏替换原则 (LSP) 的核心思想是什么？它对子类和父类的关系有何规定？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">原则</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">子类对象必须能够替代父类对象出现在任何地方，而不改变程序的正确性。这意味着子类应当实现父类的接口，并且可以在不影响系统功能的情况下替代父类对象。</div>
          </div>
          <div class="card-source">来源: 3. 里氏替换原则（Liskov Substitution Principle, LSP）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">原则</div>
          <div class="card-question">接口隔离原则 (ISP) 是如何定义客户端与接口之间的关系的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">原则</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">客户端不应被迫依赖于它不需要的接口。一个类只应当实现那些它真正使用的接口，而不应当被强制实现不需要的接口。</div>
          </div>
          <div class="card-source">来源: 4. 接口隔离原则（Interface Segregation Principle, ISP）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">原则</div>
          <div class="card-question">依赖倒置原则 (DIP) 提倡模块之间应该如何依赖？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">原则</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">高层模块不应依赖于低层模块，二者都应依赖于抽象；抽象不应依赖于细节，细节应依赖于抽象。</div>
          </div>
          <div class="card-source">来源: 5. 依赖倒置原则（Dependency Inversion Principle, DIP）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">原则</div>
          <div class="card-question">最少知识原则 (Law of Demeter, LoD) 的核心内容是什么？它对对象间的交互有何建议？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">原则</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">一个对象应该对其他对象有尽可能少的了解。换句话说，一个对象应当只与它直接的朋友交流，而不应当与它的朋友的朋友进行交互。</div>
          </div>
          <div class="card-source">来源: 6. 最少知识原则（Law of Demeter, LoD）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">目的</div>
          <div class="card-question">遵循单一职责原则（SRP）能为软件系统带来哪些具体的好处？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">目的</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">遵循单一职责原则可以使系统中的每个类都专注于单一的功能，从而提高代码的可读性和可维护性，避免因一个职责的变化影响到类的其他部分。</div>
          </div>
          <div class="card-source">来源: 1. 单一职责原则（Single Responsibility Principle, SRP）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">如何技术上实现开放封闭原则（OCP），即在不修改已有代码的情况下扩展功能？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">通过使用抽象类、接口和设计模式（如策略模式、工厂模式），可以在系统中添加新的功能，而不需要修改已有的代码，从而降低系统的风险。</div>
          </div>
          <div class="card-source">来源: 2. 开放封闭原则（Open/Closed Principle, OCP）</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在实践中，通常使用哪种技术来有效地实现依赖倒置原则（DIP）？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">通过使用依赖注入（DI）等技术，可以有效地实现依赖倒置原则，使得高层模块和低层模块都依赖于抽象层，而不是具体的实现。</div>
          </div>
          <div class="card-source">来源: 5. 依赖倒置原则（Dependency Inversion Principle, DIP）</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
